class Solution:
    def numberOfArithmeticSlices(self, A: list) -> int:
        res, length = 0, len(A)
        if length < 3:
            return 0
        cha, count = A[1] - A[0], 2
        for i in range(1, length-1):
            if A[i+1] - A[i] == cha:
                count += 1
            else:
                if count >= 3:
                    res += (count - 1) * (count - 2) // 2
                cha, count = A[i + 1] - A[i], 2
        if count >= 3:
            res += (count - 1) * (count - 2) // 2
        return res


a = Solution()
print(a.numberOfArithmeticSlices([1, 2, 3, 4]))
print(a.numberOfArithmeticSlices([1, 2, 3, 5, 6, 7]))
